package com.wn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wn.bean.Goods;
import com.wn.bean.GoodsDTO;
import com.wn.bean.GoodsDetail;
import com.wn.mapper.GoodsMapper;
import com.wn.service.IGoodsDetailService;
import com.wn.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private IGoodsDetailService goodsDetailService;

    @Override
    public List<GoodsDTO> queryGoodsDetail() {
        List<GoodsDTO> goodsDTOList = (List<GoodsDTO>) baseMapper.queryGoodsDetail();
        return goodsDTOList;
    }

    @Override
    public void saveGoods(GoodsDTO goodsDTO) {
        Goods goods = BeanUtil.copyProperties(goodsDTO, Goods.class);
        baseMapper.insert(goods);

        GoodsDetail goodsDetail = new GoodsDetail();
        goodsDetail.setGoodsId(goods.getGoodsId());
        goodsDetail.setDescription(goodsDTO.getDescription());
        goodsDetail.setBrandId(goodsDTO.getBrandId());
        goodsDetailService.save(goodsDetail);
    }
}